<?php
class SmsService
{
    public function send($mobile,$msg)
    {
        $username = "yuxiang";
        $password = "bjyxsy";
        $dt = time();
        $pwd = md5($username.$password.$dt);
        //$mobile = "18701375406";      
        
        $code = "";
        $url="username=".$username."&pwd=".$pwd;
        $url.="&mobiles=".$mobile;
        $url.="&msg=".$msg;
        $url.="&dt=".$dt;
        $url.="&code=";
        // 初始化一个 cURL 对象
        $curl = curl_init();
        
        // 设置你需要抓取的URL
        curl_setopt($curl, CURLOPT_URL, 'http://211.147.222.37:8080/sendsms/?'.$url);

        // 设置header
        curl_setopt($curl, CURLOPT_HEADER, 1);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
        // 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
        //curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        // 运行cURL，请求网页
        $data = curl_exec($curl);
        $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $body = substr($data, $headerSize);
        // 关闭URL请求
        curl_close($curl);

        // 显示获得的数据
        if(intval(trim($body))===0){
            return true;
        }else{
            return false;
        }
    }
}
